<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('新增抽奖奖品')" />
	<th:block th:include="include :: jasny-bootstrap-css" />
</head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-role-add">
			<input class="form-control" type="hidden" name="lotteryId" id="lotteryId" th:value="${lotteryId}">
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">奖项名称：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="lotteryPrizeTitle" id="lotteryPrizeTitle" placeholder="例如：一等奖" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">奖品名称：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="lotteryPrizeName" id="lotteryPrizeName" placeholder="例如：手机" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">奖品数量：</label>
				<div class="col-sm-8">
<!--					<span class="input-group-addon"><i class="fa fa-calendar"></i></span>-->
					<input class="form-control" type="number" name="prizeCnt" id="prizeCnt" placeholder="奖品数量" required onkeypress="return (/[\d]/.test(String.fromCharCode(event.keyCode)))">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">中奖概率：</label>
				<div class="col-sm-8">
					<!--					<span class="input-group-addon"><i class="fa fa-calendar"></i></span>-->
					<input class="form-control" type="number" name="prizeRate" id="prizeRate" placeholder="1~10000，代表万分之1至万分之10000" required onkeypress="return (/[\d]/.test(String.fromCharCode(event.keyCode)))">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">奖品图片：</label>
				<!--<div class="col-sm-8 file-loading">
					&lt;!&ndash;					<span class="input-group-addon"><i class="fa fa-calendar"></i></span>&ndash;&gt;
					<input class="form-control" type="file" name="uploadFile" id="uploadFile" placeholder="上传图片" required>
				</div>-->
				<div class="fileinput fileinput-new" data-provides="fileinput">
					<div class="fileinput-preview thumbnail" data-trigger="fileinput" style="width: 120px; height: 120px;"></div>
					<div>
						<span class="btn btn-white btn-file"><span class="fileinput-new">选择图片</span><span class="fileinput-exists">更改</span><input type="file" name="uploadFile" id="uploadFile" accept="image/*"></span>
						<a href="javascript:;" class="btn btn-white fileinput-exists" data-dismiss="fileinput">清除</a>
					</div>
				</div>
			</div>
		</form>
	</div>
	<th:block th:include="include :: footer" />
	<th:block th:include="include :: jasny-bootstrap-js" />
	<script type="text/javascript">
		$(function () {

		})
		$("#form-role-add").validate({
			rules:{
				onkeyup: false,
				roleName:{
					remote: {
		                url: ctx + "system/role/checkRoleNameUnique",
		                type: "post",
		                dataType: "json",
		                data: {
		                	"roleName" : function() {
		                		return $.common.trim($("#roleName").val());
		                    }
		                }
		            }
				},
				roleKey:{
					remote: {
		                url: ctx + "system/role/checkRoleKeyUnique",
		                type: "post",
		                dataType: "json",
		                data: {
		                	"roleKey" : function() {
		                        return $.common.trim($("#roleKey").val());
		                    }
		                }
		            }
				}
			},
			messages: {
		        "roleName": {
		            remote: "角色名称已经存在"
		        },
		        "roleKey": {
		            remote: "角色权限已经存在"
		        }
		    },
		    focusCleanup: true
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
	        	add();
	        }
	    }
	
		function add() {
			var lotteryId = $("input[name='lotteryId']").val();
			var lotteryPrizeTitle = $("input[name='lotteryPrizeTitle']").val();
			var lotteryPrizeName = $("input[name='lotteryPrizeName']").val();
			var prizeCnt = $("input[name='prizeCnt']").val();
			var prizeRate = $("input[name='prizeRate']").val();
			var uploadFile = $('#uploadFile')[0].files[0];
			$.ajax({
				cache : true,
				type : "POST",
				url : ctx + "biz/lotteryPrize/add",
				data : {
					"lotteryId": lotteryId,
					"lotteryPrizeTitle": lotteryPrizeTitle,
					"lotteryPrizeName": lotteryPrizeName,
					"prizeCnt": prizeCnt,
					"prizeRate": prizeRate,
					"prizeImgBase64String": uploadFile.result,
					"prizeImgName": uploadFile.name
				},
				async : false,
				error : function(request) {
					$.modal.alertError("系统错误");
				},
				success : function(data) {
					$.operate.successCallback(data);
				}
			});
		}
	</script>
</body>
</html>
